import request from '@/utils/request'

const baseUrl = '/system/role'

// 角色列表分页查询
export function getPageList(query?: SysRoleQuery, current = 1, size = 20) {
    return request({
        url: baseUrl + '/search',
        method: 'POST',
        data: {...query, current, size}
    })
}

// 删除角色
export function deleteById(id: string) {
    return request({
        url: baseUrl + '/' + id,
        method: 'DELETE'
    })
}

// 新增角色
export function add(data: SysRoleType) {
    return request({
        url: baseUrl,
        method: 'POST',
        data
    })
}

// 修改角色
export function update(data: SysRoleType) {
    return request({
        url: baseUrl,
        method: 'PUT',
        data
    })
}

// 通过角色id查询所拥有的菜单ids
export function getMenuIdsByRoleId(roleId: string) {
    return request({
        url: `${baseUrl}/${roleId}/menu/ids`,
        method: 'GET'
    })
}

// 保存角色所分配的菜单ids
export function saveRoleMenu(roleId: string, menuIds: string[]) {
    return request({
        url: `${baseUrl}/${roleId}/menu/ids`,
        method: 'POST',
        data: menuIds
    })
}

// 查询所有角色--用户分配角色下拉框
export function getRoleList() {
    return request({
        url: `${baseUrl}/list`,
        method: "GET"
    })
}